package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwFarmMerchanttypeService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by BKWJA on 2018/12/20.
 * 农家乐商户类型控制类
 */
@Slf4j
@RequestMapping("farmMerType")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwFarmMerchanttypeController extends IMoocExceptionHandler {

    @Autowired
    private XwFarmMerchanttypeService xwFarmMerchanttypeService;


    //获取全部的农家乐农家类型信息列表,不分页，按添加日期排序
    @RequestMapping("/getAllfarmMertype")
    @ResponseBody
    public JSONObject getAllfarmMertype(){
        return  xwFarmMerchanttypeService.getAllfarmMertype();
    }



    /**
     * 农家乐商户类型列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @RequestMapping("/getfarmtypelist")
    @ResponseBody
    public JSONObject getfarmtypelist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                    @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                    @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                    @RequestParam(value = "sortfild",defaultValue = "farmType_createtime") String sortfild,
                                    @RequestParam(value = "sortway",defaultValue = "desc")String sortway){
        return xwFarmMerchanttypeService.getfarmtypelist(pageindex,pagesize,starttime,endtime,sortfild,sortway);
    }

    /**
     * 修改，新增农家乐商户类型信息
     * @param farmType_encryptId  农家乐商户类型加密id
     * @param farmType_desc 农家乐商户类型文字
     * @return
     */
    @RequestMapping("/updatefarmtype")
    @ResponseBody
    public JSONObject updatefarmtype(String farmType_encryptId,String farmType_desc){
        return xwFarmMerchanttypeService.updatefarmtype(farmType_encryptId,farmType_desc);
    }

    /**
     * 根据farmType_encryptId农家乐商品类型加密id，删除对应的记录
     * @param farmType_encryptId
     * @return
     */
    @RequestMapping("/delfarmtype")
    @ResponseBody
    public JSONObject delfarmtype(String farmType_encryptId){
        return xwFarmMerchanttypeService.delfarmtype(farmType_encryptId);
    }


}
